package calmAnnotation.gui;

import java.awt.*;
import java.awt.event.*;
import java.sql.SQLException;

import javax.swing.*;
import javax.swing.table.*;

import calmAnnotation.model.CALMAnnotationManagerLauncher;

import jenamuseum.annotation.Annotation;
 
/**
 * @version 1.0 11/09/98
 */
public class ButtonEditor extends DefaultCellEditor {
  protected JButton button;
  private String    label;
  private boolean   isPushed;
  private int annotation_id;
  private int row;
  private int column;
 
  public ButtonEditor(JCheckBox checkBox) {
    super(checkBox);
    button = new JButton();
    button.setOpaque(true);
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
    	  myButton();
      }
    });
  }
 
  public Component getTableCellEditorComponent(JTable table, Object value,
                   boolean isSelected, int row, int column) {
	  //System.out.println("Button value" + value.toString());

	  annotation_id=(Integer)value;
    if (isSelected) {
      button.setForeground(table.getSelectionForeground());
      button.setBackground(table.getSelectionBackground());
    } else{
      button.setForeground(table.getForeground());
      button.setBackground(table.getBackground());
    }
    //label = (value ==null) ? "" : "suppress";
    button.setText( "suppress" );
    isPushed = true;
    return button;
  }
 
 /* public Object getCellEditorValue() {
    if (isPushed)  {
      // 
      // 
      JOptionPane.showMessageDialog(button ,row + column + ": Ouch!");
      // System.out.println(label + ": Ouch!");
    }
    isPushed = false;
    return new String( "label" ) ;
  }*/
   
  public void myButton()
  {
	  try {
		  	System.out.println("deleting annotation" + annotation_id);
			CALMAnnotationManagerLauncher.getAppModel().deleteAnnotation(annotation_id);
			CALMAnnotationManagerLauncher.getAppModel().getAllAnnotations();
			this.cancelCellEditing();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	  
  }
}